//
//  hangQingViewController.m
//  huaerjieqidai
//
//  Created by 黄军 on 2017/7/13.
//  Copyright © 2017年 $. All rights reserved.
//

#import "hangQingViewController.h"

@interface hangQingViewController ()<UIWebViewDelegate>
@property(nonatomic,strong)UIWebView *webView;
@end

@implementation hangQingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createWebView];
}

-(void)createWebView{
    self.webView  = [[UIWebView alloc]init];
    self.webView.delegate = self;
    self.webView.frame =CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.x+20, self.view.bounds.size.width, self.view.bounds.size.height-69);
//    NSURL *url = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"HTML/index" ofType:@"html" inDirectory:nil]];

    NSURL *url = [NSURL URLWithString:@"http://hej1.shqlkj.com/index/dujia"];
    
     NSURLRequest * request = [NSURLRequest requestWithURL:url];
    
    [self.webView loadRequest:request];
    
    [self.view addSubview:self.webView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    NSString *url =[NSString stringWithFormat:@"%@",request.URL];
    if ([url isEqualToString:@"http://hej1.shqlkj.com/index/login"]) {
        self.tabBarController.selectedIndex = 3;
         return NO;
    }
    
    return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView{
    NSLog(@"开始请求");
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
    NSLog(@"请求完成");
    NSString *swizzleCloseWindowJS =
    @"var script = document.createElement('script');"
    "script.type = 'text/javascript';"
    "script.text = \"window.close = function windowOnClose() { "
    "javascript:window.location='hackCloseWindowFrame://'"
    "}\";"
    "document.getElementsByTagName('head')[0].appendChild(script);";
    [webView stringByEvaluatingJavaScriptFromString:swizzleCloseWindowJS];
    
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    NSLog(@"请求失败：%@",error.userInfo);
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
